package net.qkl.chat.client.msghandler.login;

import com.cn.common.core.model.Response;
import com.cn.common.core.model.ResultCode;
import com.cn.common.core.session.Session;
import com.cn.common.core.spi.ChatSpiLoader;
import net.qkl.chat.client.module.login.handler.UserHandler;
import net.qkl.chat.client.msg.MessageHandler;

/**
 * 登录回调
 */
public class LoginHandler implements MessageHandler {

    private UserHandler userHandler;

    public LoginHandler() {
        this.userHandler = ChatSpiLoader.load(UserHandler.class);
    }

    @Override
    public void handle(Response packet, Session session) {
        if (packet.getStateCode() == ResultCode.SUCCESS) {
            userHandler.login(packet.getStateCode(), packet.getData());
        } else {
            userHandler.loginFaile(packet.getData());
        }
    }
}
